/*
 * IServiceConstants
 * 
 * Version information
 * 
 * Mar 20, 2006
 * 
 * Copyright (c) AmSoft Systems, 2006
 */
package net.amsoft.iservice.util;

import java.util.Hashtable;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;

/**
 * @author rahul
 * 
 */
public class IServiceConstants {
    private static final Logger oLog = Logger
            .getLogger(IServiceConstants.class);
    public static ResourceBundle ISERVICE_BUNDLE = ResourceBundle
            .getBundle("iservice");
    private static Hashtable<Integer, String> ohErrors = null;
    public static final String XRI_SCHEME = "xri://";
    public static final int PRIORITY_HIGHEST = 0;
    public static final String SERVICE_METADATA = getProperty(ISERVICE_BUNDLE,
            "meta.service.type");
    public static final String SERVICE_AUTHENTICATION = getProperty(
            ISERVICE_BUNDLE, "auth.service.type");
    public static final String OPENDID_AUTHENTICATION = getProperty(
            ISERVICE_BUNDLE, "openid.service.type");
    public static final String SERVICE_AUTHENTICATION_PATH = getProperty(
            ISERVICE_BUNDLE, "auth.service.path");
    public static final String IB_BANNER_KEY = getProperty(ISERVICE_BUNDLE,
            "ibroker.banner.key");
    public static final byte[] ARTIFACT_TYPE = {0x0000, 0x0004};
    public static final int REFRESH_INTERVAL = Integer.parseInt(getProperty(ISERVICE_BUNDLE,
    		"property.refresh.interval"));
    public static final String LOADBALANCER_IP = getProperty(ISERVICE_BUNDLE,
            "loadbalancer.ip");
    public static final String DOMAINS_HXRI = getProperty(ISERVICE_BUNDLE,"domains.hxri"); 
    public static final String PARAM_SERVICE_ACTIVE = "UriRequest";
    public static final String RESPONSE_URI = "text/uri-list";
    
    // XRI RESOLUTION
    private static ResourceBundle XRICLIENT_BUNDLE;
    protected static String ROOT_DEF_EQ_URI;
    protected static String ROOT_DEF_AT_URI;
    protected static String ROOT_DEF_BANG_URI;
    static {
        try {
            XRICLIENT_BUNDLE = ResourceBundle.getBundle("xriclient");
            ROOT_DEF_EQ_URI = getProperty(XRICLIENT_BUNDLE, "proxy.uri.equal");
            ROOT_DEF_AT_URI = getProperty(XRICLIENT_BUNDLE, "proxy.uri.at");
            ROOT_DEF_BANG_URI = getProperty(XRICLIENT_BUNDLE, "proxy.uri.bang");
        } catch (Exception e) {
            oLog
                    .warn("IServiceConstants: problem in loading xriclient.properties");
        }
    }

    // Log Levels
    public static final int DEBUG = 0;
    public static final int INFO = 1;
    public static final int WARN = 2;
    public static final int ERROR = 3;
    public static final int FATAL = 4;

    // EMAIL
    public static final String SMTP_HOST = "mail.smtp.host";
    public static final String EMAIL_FROM = "email.from";

    public static final void init() {
        if (ohErrors == null) {
            ohErrors = new Hashtable<Integer, String>();
            // user exception
            ohErrors.put(1001, "Password does not match");
            ohErrors.put(1000, " Email address is not valid");
            ohErrors.put(1005, " User could not be logged in");
            ohErrors.put(1002, "Synonym does not exist");
            // system exceptions
            ohErrors.put(2000, "GlobalINumber already exists ");
            ohErrors.put(2001, "Synonym already exists");
            ohErrors.put(2003, "SEP is not in corect format");
            ohErrors.put(2006, "GlobalInumber does not exist");
            ohErrors.put(2007, "Account is not active");
            ohErrors.put(2008, "SessionIndex does not exist");
            ohErrors.put(2009, "Session is invalid");
            ohErrors.put(2010, "User does not belong to this IBroker");
            ohErrors.put(2011, "Hash Collision");
            ohErrors.put(2012, "IBroker could not be  created");
            ohErrors.put(2013, "Artifact does not exist");
            ohErrors.put(2004, "IBroker not provisioned");
            ohErrors.put(2014, "Invalid Fields");
            ohErrors.put(2015, "Activation token does not exist");
            ohErrors.put(2016, "No permissions to insert the supplied Fields");
            ohErrors.put(2017, "Data Could not be deleted");
            ohErrors.put(2018,
                    "Specified Operations was not performed successfully");
            ohErrors.put(2019, "Invalid /BlankEmail Id ");
            ohErrors.put(2020, "No Synonyms Found");
            ohErrors
                    .put(2021,
                            "No permissions to update one or more of the specified fields");
            ohErrors.put(2022, "Data could not be updated");
            ohErrors.put(2023, "Synonyms could not be updated");
            ohErrors.put(2024, "Principal could not created");
            ohErrors.put(2025, "Session could not created");
            ohErrors.put(2026, "Machine Cookies could not created");
            ohErrors.put(2027, "Response could not created");
            ohErrors.put(2028, "InSufficient Data");
            ohErrors.put(2029, "Invalid Session type specified");
            ohErrors.put(2030, "No matching record found ");
            ohErrors.put(2031, "IBroker already exist");
            ohErrors.put(2032, "Machine Cookie Does Not exist");
            ohErrors.put(2033, "Session Does Not exist");
            ohErrors.put(2034, "Iname/Inumber can't be resolved");
            ohErrors.put(2035, "Session does not belong to Principal");
            ohErrors.put(2036, "This Method is currently not implemented");
            ohErrors.put(2037, "I-Link already exist");
            ohErrors.put(2038, "No active Session found");

            ohErrors.put(2100,
                    "Contact Page does not exist for the given synonym");

            ohErrors.put(101, "Duplicate");
            ohErrors.put(102, "Parse Error");
        }
    }

    public static final String getError(int iErrorCode)
            throws NullPointerException {
        if (ohErrors == null) {
            init();
        }
        return (String) ohErrors.get(iErrorCode);
    }

    private static final String getProperty(ResourceBundle oBundle, String key) {
        try {
            return oBundle.getString(key);
        } catch (Exception e) {
            oLog.fatal("getProperty(): key: [" + key + "] not found");
            return "";
        }
    }
}
